package com.atguigu.common;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 *自定义源数据填充 ->creat_user creat_time  update_time....
 *
 */
@Component
@Slf4j
public class MyMeteDataHandler implements MetaObjectHandler {

	/**
	 * 执行插入操作时进入此方法
	 * @param metaObject
	 * TODO 公共字段自动填充
	 */
	@Override
	public void insertFill(MetaObject metaObject) {
		log.info("insert公共字段自动填充");
		log.info(metaObject.toString());
		//这里面的name参数需为实体类中的成员变量
	    metaObject.setValue("gmtCreate", LocalDateTime.now());
	    metaObject.setValue("gmtModified",LocalDateTime.now());


	}

	@Override
	public void updateFill(MetaObject metaObject) {
        log.info("update公共字段自动填充");
        metaObject.setValue("gmtModified",LocalDateTime.now());
	}
}
